package com.func;

import java.util.function.Function;

/**
 * https://zhuanlan.zhihu.com/p/357918015
 * 如何生产一个函数（返回值是函数式接口）
 *
 * @author: chenhs
 * @date: Created in 10:03 2022/7/12
 **/
public class ProduceFunction {

    Function<String, String> produce() {

        //普通写法
        /*return new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.toLowerCase(Locale.ROOT);
            }
        };*/

        //lambda表达式
        /*
        return (s) -> s.toLowerCase(Locale.ROOT);
        */

        //方法引用
        return String::toLowerCase;
    }


    public static void main(String[] args) {
        ProduceFunction pf = new ProduceFunction();
        Function<String, String> f = pf.produce();
        System.out.println(f.apply("KEKE"));
    }
}
